<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('主机状态信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            节点：
                            <select name="nodeCode" th:with="nodes=${@node.getCacheNodeInfoAll()}">
                                <option value="">所有</option>
                                <option th:each="node:${nodes}" th:title="${node.ip}" th:value="${node.nodeCode}"
                                        th:text="${node.hostname}"></option>
                            </select>
                        </li>
                        <li>
                            主机状态：
                            <select name="status" th:with="type=${@dict.getType('survive_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var surviveStatusDatas = [[${@dict.getType('survive_status')}]];
    var prefix = ctx + "system/nodeStatus";

    $(function () {
        queryList();
    });

    function queryList() {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            sortName: "nodeCode",
            modalName: "节点",
            columns: [{
                checkbox: true
            },
            {
                field: 'id',
                title: '编号',
                sortable: true,
                visible: false
            },
            {
                field: 'nodeCode',
                title: '节点编号',
                sortable: true
            },
            {
                field: 'deployIp',
                title: 'IP地址'
            },
            {
                field: 'detectionTime',
                title: '更新时间'
            },
            {
                field: 'status',
                title: '状态',
                align: 'center',
                sortable: true,
                formatter: function (value, row, index) {
                    return $.table.selectDictLabel(surviveStatusDatas, value);
                }
            },
            {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    var isStart = row.status == 1;
                    var isStop = row.status == 0;
                    var isStartActivity = row.status == 2;
                    if (isStop) {
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="online(\'' + row.id + '\')"><i class="fa fa-power-off"></i>上线</a> ');
                    } else if (isStart) {
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="offline(\'' + row.id + '\')"><i class="fa fa-power-off"></i>下线</a> ');
                    } else {
                        var item = '<a class="btn btn-warning btn-xs" href="javascript:void(0)" disabled><i class="fa fa-power-off"></i>' + (isStartActivity ? '启动' : '停止') + '中</a> ';
                        actions.push(item);
                    }
                    /*var more = [];
                    more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='updateNodeLoginCredentials(" + row.id + ")'><i class='fa fa-key'></i>修改登录用户名密码</a> ");
                    actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');*/
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    }

    /* 监控代理上线 */
    function online(id) {
        var data = {"id": id};
        $.operate.save(prefix + "/online", data);
    }

    /* 监控代理下线 */
    function offline(id) {
        var data = {"id": id};
        $.operate.save(prefix + "/offline", data);
    }

</script>
</body>
</html>